package com.qt.eurekaclientuser.controller;

import com.qt.eurekaclientuser.entity.Product;
import com.qt.eurekaclientuser.service.ProductService;
import com.qt.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;


/**
 * Despription:
 *
 * @Autor: xusl
 * @Date: 2019/6/19 11:31
 * @Version: 1.0
 **/
@RestController
@RequestMapping("/product")
@RefreshScope
public class ProductController {

    @Autowired
    private ProductService productService;

    @Value("${user.key}")
    private String key;

    @GetMapping(value = "/query_page")
    public Result queryByPage(@RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize,
                              @RequestParam(value = "pn", required = false, defaultValue = "1") Integer pn,
                              @RequestBody Product product) {
        Page<Product> productPageInfo = productService.queryByPage(pageSize, pn, product);
        Result<Object> result = Result.success();
        result.setData(productPageInfo);
        return result;

    }


    @PostMapping(value = "/product_add")
    public Result productAdd(Product product) {

        boolean saveFlag = productService.addOne(product);
        Result result = new Result();
        result.setSuccess(saveFlag);
        return result;

    }

    /**
     * @Description: 测试springcloud bus 刷新云端配置文件 测试方法  开启rabbitmq  打开 http://localhost:10000/actuator/bus-refresh  post请求（config-server模块）
     * @Author: xusl
     * @Date: 2019/6/20 14:37
     * @Param: []
     * @return: com.qt.result.Result
     **/
    @GetMapping("/test")
    public Result test() {
        Result<Object> result = Result.success();
        result.setData(key);
        return result;
    }

}
